home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 015 / prtspool.arc / BUFFERP.ASM next >
Encoding:
Assembly Source File  |  1985-03-08  |  12.6 KB  |  647 lines

  1. ; FLASH PRINT control program
  2.  
  3.     PAGE 60,132
  4. CODE    SEGMENT
  5.     ASSUME CS:CODE, DS:CODE, ES:CODE, SS:CODE
  6.  
  7. ; COM file  e.i. assume IP = 100, SP = FFFE.
  8. ; Since this is a com file, it will be loaded in the lowest available memory
  9. ; and all of the memory will be allocated to this program. See page 4-2
  10. ; in Microsoft's Programmer's Reference Manual for all the other EXEC system
  11. ; call information.
  12.  
  13. KEYBOARD_NO_ECHO EQU    8        ; msdos function call equates
  14. DISPLAY_CHAR    EQU    2
  15. DISPLAY_STRING    EQU    9
  16. TERMINATE    EQU    4CH
  17.  
  18. CR            EQU    0DH
  19. LF            EQU    0AH
  20. BUFFER_INT_NUMBER    EQU    65H
  21.  
  22.     ORG 100H
  23. BEGIN:
  24.     JMP S1
  25. ; data
  26. HEADER        DB "Seattle Computer Product's FLASH PRINT control program. Version 2.0",cr,lf,lf,"$"
  27. NOT_INSTALLED    DB "FLASH PRINT is not installed.",cr,lf,"$"
  28. NOT_VALID_PORT    DB "The output port does not exist",cr,lf,"$"
  29. LINE1        DB "The number of characters in the buffer: $"
  30. LINE2        DB "The size of the buffer in characters: $"
  31. LINE3        DB "The port being used with the printer: $"
  32. LINE4        DB "The priority of the printer (1 lowest, 200 highest): $"
  33. MENU        DB CR,LF,"Choose the number of one of the following command options.",cr,lf
  34.         DB "1.) Clear the buffer",cr,lf
  35.         DB "2.) Change the port to use with the printer",cr,lf
  36.         DB "3.) Change the priority",cr,lf
  37.         DB "4.) Exit the program",cr,lf,"$"
  38. NUMBER        DB "Number: ","$"
  39. PORT_MENU    DB CR,LF,LF,"Choose the port to use with the printer.",cr,lf
  40.         DB "1.) LPT1",cr,lf
  41.         DB "2.) LPT2",cr,lf
  42.         DB "3.) LPT3",cr,lf
  43.         DB "4.) COM1",cr,lf
  44.         DB "5.) COM2",cr,lf
  45.         DB "6.) Exit the program",cr,lf,"$"
  46. NOT_AVALIABLE    DB "The port chosen is not in the system",cr,lf,"$"
  47. BUFFER_CLEARED    DB "The buffer is empty",cr,lf,"$"
  48. NEW_PORT    DB "The new port to use with the printer is $"
  49. LPT1_MESS    DB "LPT1",CR,LF,"$"
  50. LPT2_MESS    DB "LPT2",CR,LF,"$"
  51. LPT3_MESS    DB "LPT3",CR,LF,"$"
  52. COM1_MESS    DB "COM1",CR,LF,"$"
  53. COM2_MESS    DB "COM2",CR,LF,"$"
  54. NEW_PRIORITY    DB "Input the new priority: $"
  55. NOTHING_DONE    DB "Nothing was done",cr,lf,"$"
  56. YOU_SURE    DB "You sure you what to clear the buffer? (y=yes) $"
  57. CRLF        DB CR,LF,"$"
  58. SPACE        DB "  $"
  59. NOT_VALID_NUMBER DB cr,lf,"invalid number",cr,lf,"$"
  60.  
  61. PORT_NUMBER        DB ?
  62. PORT_TYPE        DB ?
  63. BUFFER_SIZE        DW ?
  64. CHARACTERS_IN_BUFFER    DW ?
  65. PRIORITY        DW ?
  66. ; end of data
  67.  
  68. ; macros
  69. PRINT    MACRO    MESSAGE
  70.     MOV AH, DISPLAY_STRING
  71.     MOV DX, OFFSET MESSAGE
  72.     INT 21H
  73.     ENDM
  74.  
  75. BUFFER_INPUT    MACRO    SIZE_OF_BUFFER
  76.     LOCAL I2, BUFFER, NUM_OF_CHARS, BUFFER2
  77. ; This macro inputs characters from the keyboard with echo and stores them in memory.
  78. ; The string of characters is terminated with two bytes of 0.
  79. ; enter: ds = cs
  80. ; exit: al = # of characters typed not including the CR
  81. ;    ds:si -> first char. of the string typed
  82.  
  83.     JMP I2
  84. BUFFER        DB SIZE_OF_BUFFER + 1
  85. NUM_OF_CHARS    DB ?
  86. BUFFER2        DB SIZE_OF_BUFFER DUP(?)
  87.         DW ?
  88. I2:
  89.     MOV AH, 0AH            ; buffer keyboard input
  90.     MOV DX, OFFSET BUFFER
  91.     INT 21H
  92.     
  93.     MOV AL, [NUM_OF_CHARS]        ; end the string with 0,0
  94.     MOV AH, 0
  95.     MOV SI, OFFSET BUFFER2
  96.     ADD SI, AX
  97.     MOV [SI], WORD PTR 0
  98.     SUB SI, AX
  99.     
  100.     ENDM
  101. ; end of macros
  102.  
  103. S1:
  104.     PRINT HEADER            ; print "Seattle Computer Product's FLASH PRINT ..."
  105.     
  106.     MOV AH, 35H            ; get the buffer vector
  107.     MOV AL, BUFFER_INT_NUMBER
  108.     INT 21H                ; es:bx = vector
  109.     
  110.     CMP BX, 0            ; determine if the device driver is installed
  111.     JNZ B1
  112.     MOV AX, ES
  113.     CMP AX, 0
  114.     JNZ B1
  115.     
  116.     PRINT NOT_INSTALLED        ; print "FLASH PRINT is not installed."
  117.     JMP TERMIN_ATE
  118. B1:
  119.     MOV AX, CS            ; restore es = cs
  120.     MOV ES, AX
  121.  
  122.     MOV AX, 1            ; get port # and type
  123.     INT BUFFER_INT_NUMBER
  124.     MOV [PORT_NUMBER], BL
  125.     MOV [PORT_TYPE], BH
  126.     
  127.     MOV AX, 3            ; get buffer size
  128.     INT BUFFER_INT_NUMBER
  129.     MOV [BUFFER_SIZE], BX
  130.     
  131.     MOV AX, 4            ; get # of char. in the buffer
  132.     INT BUFFER_INT_NUMBER
  133.     MOV [CHARACTERS_IN_BUFFER], BX
  134.     
  135.     MOV AX, 6            ; get the priority
  136.     INT BUFFER_INT_NUMBER
  137.     MOV [PRIORITY], BX
  138.  
  139.     PRINT LINE1            ; print "The number of characters in the buffer:"
  140.     
  141.     MOV AX, [CHARACTERS_IN_BUFFER]
  142.     CALL BIN2DEC
  143.     CALL PRINTBXCXDX
  144.     PRINT CRLF        
  145.     
  146.     PRINT LINE2            ; print "The size of the buffer in characters:"
  147.     
  148.     MOV AX, [BUFFER_SIZE]
  149.     CALL BIN2DEC
  150.     CALL PRINTBXCXDX
  151.     PRINT CRLF
  152.     
  153.     PRINT LINE3            ; print "The port being used with the printer:"
  154.     
  155.     MOV AH, [PORT_TYPE]
  156.     MOV AL, [PORT_NUMBER]    
  157.     CALL PRINT_PORT
  158.     
  159.     PRINT LINE4            ; print "The priority of the printer (1 lowest, 65536 highest):"
  160.     
  161.     MOV AX, [PRIORITY]
  162.     CALL BIN2DEC
  163.     CALL PRINTBXCXDX
  164.     PRINT CRLF
  165.         
  166.     PRINT MENU            ; print the menu
  167. B2:    
  168.     PRINT NUMBER            ; print "Number: "
  169.     
  170.     MOV AH, KEYBOARD_NO_ECHO    ; wait for a number to be typed
  171.     INT 21H
  172.  
  173.     CMP AL, CR
  174.     JE EXIT8
  175.     
  176.     PUSH AX                ; echo every thing except cr
  177.     MOV AH, DISPLAY_CHAR
  178.     MOV DL, AL
  179.     INT 21H
  180.  
  181.     PRINT SPACE            ; print two spaces
  182.     POP AX
  183.     
  184.     CMP AL, "1"            ; jump to the correct command
  185.     JE CLEAR_THE_BUFFER
  186.     CMP AL, "2"
  187.     JNE B23
  188.     JMP CHANGE_PORT
  189. B23:
  190.     CMP AL, "3"
  191.     JE CHANGE_PRIORITY
  192.     CMP AL, "4"
  193.     JE EXIT8
  194.     JMP B2
  195.  
  196. EXIT8:
  197.     PRINT CRLF
  198.     JMP TERMIN_ATE
  199.  
  200. CLEAR_THE_BUFFER:
  201.     PRINT YOU_SURE            ; print "Are you sure you want to clear the buffer? (y=yes) "
  202.     
  203.     MOV AH, KEYBOARD_NO_ECHO    ; wait for something to be typed
  204.     INT 21H
  205.  
  206.     CMP AL, CR
  207.     JE B245
  208.  
  209.     PUSH AX                ; echo everything except cr
  210.     MOV AH, DISPLAY_CHAR
  211.     MOV DL, AL
  212.     INT 21H
  213.     
  214.     PRINT SPACE            ; print two spaces
  215.     POP AX
  216.  
  217.     AND AL, 0DFH            ; convert the something to upper case
  218.     
  219.     CMP AL, "Y"
  220.     JE B25
  221. B245:
  222.     PRINT NOTHING_DONE        ; print "Nothing was done"
  223.     JMP TERMIN_ATE
  224. B25:    
  225.     MOV AX, 0            ; flush the buffer
  226.     INT BUFFER_INT_NUMBER
  227.  
  228.     PRINT BUFFER_CLEARED        ; print "The buffer is empty"    
  229.     JMP TERMIN_ATE
  230.  
  231. CHANGE_PRIORITY:
  232.     PRINT NEW_PRIORITY        ; print "Input the new priority"
  233.     
  234.     BUFFER_INPUT  5            ; input max. of 5 character from the keyboard with echo
  235.     CMP AL, 0            ; if no characters were typed exit
  236.     JNZ B26
  237.     JMP TERMIN_ATE
  238. B26:    
  239.     CALL ASCBIN            ; conver the ascii characters to binary
  240.     PUSH AX    
  241.  
  242.     PRINT CRLF
  243.  
  244.     LODSB                ; if the first non convertable character is a 0, then it was a good #.
  245.     CMP AL, 0
  246.     POP AX
  247.     JNZ B265
  248.  
  249.     CMP AX, 0            ; the priority must be between 1 and 200
  250.     JE B265
  251.     CMP AX, 200            
  252.     JA B265
  253.     JMP B27
  254.  
  255. B265:
  256.     PRINT NOT_VALID_NUMBER
  257.     JMP CHANGE_PRIORITY
  258. B27:    
  259.     MOV BX, AX            ; set the new priority
  260.     MOV AX, 5
  261.     INT BUFFER_INT_NUMBER
  262.  
  263.     PRINT CRLF    
  264.     JMP TERMIN_ATE
  265.     
  266. CHANGE_PORT:
  267.     PRINT PORT_MENU            ; print the port menu
  268. B3:
  269.     PRINT NUMBER            ; print "Number: "
  270.     
  271.     MOV AH, KEYBOARD_NO_ECHO    ; wait for a number to be typed
  272.     INT 21H
  273.  
  274.     CMP AL, CR
  275.     JE EXIT9
  276.     
  277.     PUSH AX                ; echo every thing except cr
  278.     MOV AH, DISPLAY_CHAR
  279.     MOV DL, AL
  280.     INT 21H
  281.  
  282.     PRINT SPACE            ; print two spaces
  283.     POP AX
  284.  
  285.     CMP AL, "1"            ; jump to the correct command
  286.     JE LPT1
  287.     CMP AL, "2"
  288.     JE LPT2
  289.     CMP AL, "3"
  290.     JE LPT3
  291.     CMP AL, "4"
  292.     JNE B35
  293.     JMP COM1
  294. B35:
  295.     CMP AL, "5"
  296.     JNE B4
  297.     JMP COM2
  298. B4:
  299.     CMP AL, "6"
  300.     JE EXIT9
  301.     JMP B3
  302.  
  303. EXIT9:
  304.     PRINT CRLF
  305.     JMP TERMIN_ATE
  306. LPT1:
  307.     MOV BX, 0000H
  308.     CALL GET_PORT_ADDRESS        ; determine if this port is in the system
  309.     CMP DX, 0
  310.     JNZ  B5
  311.     JMP THIS_PRN_NOT_AVALIABLE
  312. B5:    
  313.     PRINT NEW_PORT            ; print "The new port to use with the printer is "
  314.     PRINT LPT1_MESS            ; print "LPT1."
  315.     
  316.     MOV AX, 2            ; use lpt1 for the output port
  317.     MOV BL, 0            ; port number
  318.     MOV BH, 1            ; port type = parallel
  319.     INT BUFFER_INT_NUMBER
  320.     JMP TERMIN_ATE
  321.     
  322. LPT2:
  323.     MOV BX, 0001
  324.     CALL GET_PORT_ADDRESS        ; determine if this port is in the system
  325.     CMP DX, 0
  326.     JNZ B6
  327.     JMP THIS_PRN_NOT_AVALIABLE
  328. B6:    
  329.     PRINT NEW_PORT            ; print "The new port to use with the printer is "
  330.     PRINT LPT2_MESS            ; print "LPT2."
  331.         
  332.     MOV AX, 2
  333.     MOV BL, 1    ; port number
  334.     MOV BH, 1    ; port type = parallel
  335.     INT BUFFER_INT_NUMBER
  336.     JMP TERMIN_ATE
  337.  
  338. LPT3:
  339.     MOV BX, 0002
  340.     CALL GET_PORT_ADDRESS        ; determine if this port is in the system
  341.     CMP DX, 0
  342.     JZ THIS_PRN_NOT_AVALIABLE
  343.     
  344.     PRINT NEW_PORT            ; print "The new port to use with the printer is "
  345.     PRINT LPT3_MESS            ; print "LPT3."
  346.     
  347.     MOV AX, 2
  348.     MOV BL, 2    ; port number (0,1,2)
  349.     MOV BH, 1    ; port type = parallel
  350.     INT BUFFER_INT_NUMBER
  351.     
  352.     JMP TERMIN_ATE
  353.  
  354. COM1:
  355.     MOV BX, 0100H
  356.     CALL GET_PORT_ADDRESS        ; determine if this port is in the system
  357.     CMP DX, 0
  358.     JZ THIS_PRN_NOT_AVALIABLE
  359.     
  360.     PRINT NEW_PORT            ; print "The new port to use with the printer is "
  361.     PRINT COM1_MESS            ; print "COM1."
  362.     
  363.     MOV AX, 2
  364.     MOV BL, 0    ; port number
  365.     MOV BH, 0    ; port type = serial
  366.     INT BUFFER_INT_NUMBER
  367.     JMP TERMIN_ATE
  368.  
  369. COM2:
  370.     MOV BX, 0101H
  371.     CALL GET_PORT_ADDRESS        ; determine if this port is in the system
  372.     CMP DX, 0
  373.     JZ THIS_PRN_NOT_AVALIABLE
  374.     
  375.     PRINT NEW_PORT            ; print "The new port to use with the printer is "
  376.     PRINT COM2_MESS            ; print "COM2."
  377.     
  378.     MOV AX, 2
  379.     MOV BL, 1    ; port number
  380.     MOV BH, 0    ; port type = serial
  381.     INT BUFFER_INT_NUMBER
  382.     JMP TERMIN_ATE
  383.  
  384. THIS_PRN_NOT_AVALIABLE:
  385.     PRINT NOT_AVALIABLE
  386.     JMP B3
  387.  
  388. TERMIN_ATE:
  389.     MOV AH, TERMINATE        ; return to msdos
  390.     INT 21H
  391.  
  392. ;--------------------------------------------------------------------
  393.  
  394. PRINTBXCXDX    PROC
  395. ; print registers bx, cx, dx if they are not spaces
  396.     PUSH DX
  397.     PUSH DX
  398.  
  399.     CMP BH, " "
  400.     JE P1
  401.  
  402.     MOV AH, DISPLAY_CHAR
  403.     MOV DL, BH
  404.     INT 21H
  405. P1:
  406.     CMP BL, " "
  407.     JE P2
  408.  
  409.     MOV AH, DISPLAY_CHAR
  410.     MOV DL, BL
  411.     INT 21H
  412. P2:
  413.     CMP CH, " "
  414.     JE P3
  415.  
  416.     MOV AH, DISPLAY_CHAR
  417.     MOV DL, CH
  418.     INT 21H
  419. P3:
  420.     CMP CL, " "
  421.     JE P4
  422.  
  423.     MOV AH, DISPLAY_CHAR
  424.     MOV DL, CL
  425.     INT 21H
  426. P4:
  427.     MOV AH, DISPLAY_CHAR
  428.     POP DX
  429.     CMP DH, " "
  430.     JE P5
  431.     MOV DL, DH
  432.     INT 21H
  433. P5:
  434.     MOV AH, DISPLAY_CHAR
  435.     POP DX
  436.     INT 21H
  437.  
  438.     RET
  439. PRINTBXCXDX    ENDP
  440.  
  441. ;--------------------------------------------------------------------
  442.  
  443. BIN2DEC    PROC
  444. ; Convert a two byte binary number to a six byte ascii decimal number.
  445. ; call: ax = binary number
  446. ;    es = cs = ds
  447. ; return: bxcxdx = ascii decimal number
  448. ; registers changed: bx cx dx
  449. ; algorithm used:
  450. ; REPEAT digit = (x mod 10) + '0'; x = x DIV 10 UNTIL x = 0
  451.     
  452.     PUSHF
  453.     PUSH AX
  454.     PUSH SI
  455.     PUSH DI
  456.  
  457.     CLD            ; auto increment
  458.     MOV DI, OFFSET SCRATCH    ; work space
  459.     MOV SI, DI
  460.     PUSH AX
  461.     MOV AX, 2020H
  462.     STOSW
  463.     STOSW
  464.     STOSW
  465.     POP AX
  466.     MOV DI, SI
  467.     MOV BX, 10
  468.  
  469. REPEAT3:    
  470.     XOR DX, DX        ; get the first digit
  471.     DIV BX            ; dxax/bx = ax R dx
  472.     ADD DX, "0"
  473.     PUSH AX
  474.     MOV AL, DL
  475.     STOSB            ; mov es:[di], al
  476.     POP AX
  477.     OR AX, AX
  478.     JNZ REPEAT3
  479.  
  480.     LODSW
  481.     MOV DX, AX
  482.     LODSW
  483.     MOV CX, AX
  484.     LODSW
  485.     MOV BX, AX
  486.  
  487.     POP DI
  488.     POP SI
  489.     POP AX
  490.     POPF
  491.     RET
  492.  
  493. SCRATCH    DB 6 DUP(9)
  494. BIN2DEC    ENDP
  495.  
  496. ;--------------------------------------------------------------------
  497.  
  498. GET_PORT_ADDRESS    PROC
  499. ; call: bh = port type (0 com, 1 if parallel)
  500. ;    bl = port_number (0, 1, 2)
  501. ; return: dx = port address
  502.     PUSH AX
  503.     PUSH ES
  504.     PUSH SI
  505.  
  506.     MOV    AX,0040H    ; use es:si to get the port address
  507.     MOV    ES,AX        ; the com and parallel ports are at 40:0 to 40:0010
  508.     MOV    SI,8    
  509.     CMP    BH, 0
  510.     JNZ    G1
  511.     MOV     SI, 0
  512. G1:
  513.     MOV    AL, BL
  514.     CBW        
  515.     ADD    SI,AX    
  516.     ADD    SI,AX    
  517.     MOV    DX,ES:[SI]
  518.     
  519.     POP SI
  520.     POP ES
  521.     POP AX
  522.     RET
  523. GET_PORT_ADDRESS    ENDP
  524.  
  525. ;--------------------------------------------------------------------
  526.  
  527. PRINT_PORT    PROC
  528. ; print the port type (LPT1, LPT2, LPT3, COM1, COM2) on the screen
  529. ; call:    ah = port type (0 = com, 1 = parallel)
  530. ;    al = port number (0, 1, 2)
  531. ; return: carry set if al or ah are out of range
  532.     CMP AH, 0
  533.     JZ COM
  534.     CMP AH, 1
  535.     JZ LPT
  536.     JMP ERROR3
  537. COM:    
  538.     CMP AL, 0
  539.     JZ COM_ONE
  540.     CMP AL, 1
  541.     JZ COM_TWO
  542.     JMP ERROR3
  543. LPT:
  544.     CMP AL, 0
  545.     JZ LPT_ONE
  546.     CMP AL, 1
  547.     JZ LPT_TWO
  548.     CMP AL, 2
  549.     JZ LPT_THREE
  550.     JMP ERROR3
  551. COM_ONE:
  552.     PRINT COM1_MESS
  553.     RET
  554. COM_TWO:
  555.     PRINT COM2_MESS
  556.     RET
  557. LPT_ONE:
  558.     PRINT LPT1_MESS
  559.     RET
  560. LPT_TWO:
  561.     PRINT LPT2_MESS
  562.     RET
  563. LPT_THREE:
  564.     PRINT LPT3_MESS
  565.     RET
  566. ERROR3:
  567.     STC
  568.     RET
  569. PRINT_PORT    ENDP
  570.     
  571. ;--------------------------------------------------------------------
  572.  
  573. ASCBIN    PROC
  574. COMMENT *
  575. DECIMAL ASCII TO BINARY CONVERSION UTILITY
  576. Dr. Dobb's  September 82 , page 65
  577.     
  578. Scans past any leading blanks.  Terminates on the first illegal character and
  579. returns its address.
  580. call:
  581.     SI = address of ASCII string containing any of the characters
  582.          +-.0123456789
  583. return:
  584.     AX = signed binary result
  585.     CX = number of digits after the decimal, or -1 if none
  586.     SI = address of first non-convertible character
  587. registers:
  588.     direction flag is cleared
  589.     
  590.     *
  591.  
  592.     CLD
  593.     PUSH DX
  594.     PUSH BX
  595.     XOR BX,BX
  596.     MOV CX,-1
  597. AB1:
  598.     CMP BYTE PTR [SI],' '
  599.     JNZ AB2
  600.     INC SI
  601.     JMP AB1
  602. AB2:
  603.     PUSH SI
  604.     CMP BYTE PTR [SI],'+'
  605.     JZ AB25
  606.     CMP BYTE PTR [SI],'-'
  607.     JNZ AB3
  608. AB25:
  609.     INC SI
  610. AB3:
  611.     LODSB
  612.     CMP AL,'.'
  613.     JNZ AB4
  614.     XOR CX,CX
  615.     JMP AB3
  616. AB4:
  617.     CMP AL,'0'
  618.     JB AB5
  619.     CMP AL,'9'
  620.     JA AB5
  621.     AND AX,0FH
  622.     XCHG AX,BX
  623.     MOV DX,10
  624.     MUL DX
  625.     ADD BX,AX
  626.     OR CX,CX
  627.     JS AB3
  628.     INC CX
  629.     JMP AB3
  630. AB5:
  631.     DEC SI
  632.     MOV AX,BX
  633.     POP BX
  634.     CMP BYTE PTR [BX],'-'
  635.     JNZ AB6
  636.     NEG AX
  637. AB6:
  638.     POP BX
  639.     POP DX
  640.     RET
  641. ASCBIN    ENDP
  642.  
  643. ;--------------------------------------------------------------------
  644.  
  645. CODE    ENDS
  646.     END BEGIN
  647.